package com.example.myBatis.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Mapper
public interface UserInfo2Mapper {
    //动态SQL练习
    //假如此时性别是否为空
    //Insert into userinfo(username,password,age,gender,phone) values(#{username},#{password},#{age],#{gender},#{phone})
    @Insert("<script>" +
            "Insert into userinfo(username,password,age," +
            "<if test='gender!=null'>gender,</if>" +
            "phone)" +
            "values(#{username},#{password},#{age}," +
            "<if test='gender!=null'>#{gender},</if>" +
            "#{phone})" +
            "</script>")
    Integer insert(UserInfo userInfo);
    Integer insertByXML(UserInfo userInfo);

    List<UserInfo> selectByCondition(UserInfo userInfo);
    @Select("<script>" +
            "Select *from  userinfo " +
            "<where> " +
            "<if test= \"username!=null\">"+
           "username = #{username}" +
            "</if>"+
            "<if test= \"age!=null\"> "+
            "and age=#{age}"+
            " </if>  "+
            "<if test=\"gender!=null\">"+
            "and  gender=#{gender}"+
            "</if>"+
            "</where>"+
            "</script>")
    List<UserInfo> selectByCondition3(UserInfo userInfo);
    Integer updateByCondition(UserInfo userInfo);
    Integer batchDelete(@Param("MMM") List<Integer> MMM);

}
